
import webserver.WebServer;
import com.vng.jcore.common.Config;
import com.vng.jcore.common.LogUtil;
import java.io.File;
import java.util.TimeZone;

public class ServiceDaemon
{
    private static org.apache.log4j.Logger _log = org.apache.log4j.Logger.getLogger(ServiceDaemon.class);

    public static void main(String[] args) throws Exception
    {		
	LogUtil.init();	
	String pidFile = System.getProperty("pidfile");	
	try
	{
	    // For linux service running mode
	    if (pidFile != null)
		new File(pidFile).deleteOnExit();
	    
	    // Set default time zone
              System.out.println(Config.getHomePath());
	    TimeZone.setDefault(TimeZone.getTimeZone(Config.getParam("time_zone", "tz")));

            if(Integer.parseInt(Config.getParam("config", "update")) ==1)
                config.UtilConfig.updateConfigDB();
            config.ConfigModels.getInstance().getDataConfig();
	    //start thrirt read
	    WebServer.getSingleton().start();
            
           
	}
	catch (Throwable e)
	{
	    String msg = "Exception encountered during startup.";
	    _log.error(msg, e);

	    // try to warn user on stdout too, if we haven't already detached
	    System.out.println(msg);
	    _log.error("Uncaught exception: " + e.getMessage());

	    System.exit(3);
	}
    }
}
